package com.huidao.servlet.Goods;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.service.GoodsService;
import com.huidao.service.GoodsServiceImp;

public class GetGoodsListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public GetGoodsListServlet() {
	}

	protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {
		String keyName = request.getParameter("namekey");	
		System.out.println(keyName);
		String gid =request.getParameter("id");
		long id = 0;
		if(gid!=null){
			id=Long.parseLong(gid);
		}
		int currentpage = 1;
		String curr = request.getParameter("currentpage");
		if(curr!=null){
			currentpage = Integer.parseInt(curr);
		}
		GoodsService gs = new GoodsServiceImp();
		int totalpage = gs.getTotalPage(keyName, id);
		request.setAttribute("totalpage", totalpage);
		if(currentpage>totalpage){
			currentpage=totalpage;
		}
		response.getWriter().print(gs.getGoodsList(keyName, currentpage, id));
	}

	protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
